package com.svili.model;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.mybatis.jpa.annotation.*;

import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户信息
 *
 * @Table和Id是必须的
 *
 * @author svili
 * @date 2016年8月10日
 *
 */
//@Entity
/* {@Table}非必须,若无此注解,将类名解析为下划线风格 做为表名 */
//@Table(name = "user")
//@CatTableFlag("flag")
@TableName("user")
public class User  extends Model {



	/* {@Id}必须,主键标识,{@Column}非必须,若无此注解,或其name="",将字段名解析为下划线风格 做为SQL列名 */
	@TableId(value = "user_id", type = IdType.AUTO)
	private Integer userId;

	@TableField("dept_Id")
	private Integer deptId;


	@TableField("user_Name")
	@Like
	private String userName;

	@TableField("login_Name")
	@LLike
	private String loginName;

	@RLike
	@TableField(value="password_alias", fill = FieldFill.INSERT)
	private String password;

	@TableField("mobile_Phone")
	@Between
	//@DataPermisson("phone")
	private String mobilePhone;

	@TableField(exist=false)
	private String flag = "test";

	@OneToOne(mappedBy="dept_id")
	@TableField(exist=false)
	private Dept dept;

	@Version
	@TableField("version")
	private Integer version;

	@OneToMany(mappedBy="user_id")
	@TableField(exist=false)
	private List<Role> roles;

    public List<Role> getRoles()
    {
        return roles;
    }

    public void setRoles(List<Role> roles)
    {
        this.roles = roles;
    }

    @Transient//jpa注解 两个都支持，但是如果使用mp的功能的话请使用@TableField(exist=false)注解
	@TableField(exist=false)
    private Map<String,String> between = new HashMap<>();

	@Transient//jpa注解 两个都支持，但是如果使用mp的功能的话请使用@TableField(exist=false)注解
	@TableField(exist=false)
	private Map<String,String> dataPermissin = new HashMap<>();

	@Transient//jpa注解 两个都支持，但是如果使用mp的功能的话请使用@TableField(exist=false)注解
	@TableField(exist=false)
	private Map<String,String> inFilter = new HashMap<>();

	public User() {
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getDeptId() {
		return deptId;
	}

	public void setDeptId(Integer deptId) {
		this.deptId = deptId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (userId == null) {
			if (other.userId != null)
				return false;
		} else if (!userId.equals(other.userId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

    public String getFlag()
    {
        return flag;
    }

    public void setFlag(String flag)
    {
        this.flag = flag;
    }

    public Map<String, String> getBetween()
    {
        return between;
    }

    public void setBetween(Map<String, String> between)
    {
        this.between = between;
    }

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public Map<String, String> getDataPermissin() {
		Map<String, String> defaultDataPermissin = new HashMap<String, String>();
		defaultDataPermissin.put("phone","'1'");
		return defaultDataPermissin;
	}

	public void setDataPermissin(Map<String, String> dataPermissin) {
		this.dataPermissin = dataPermissin;
	}

	public Map<String, String> getInFilter() {
		return inFilter;
	}

	public void setInFilter(Map<String, String> inFilter) {
		this.inFilter = inFilter;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}
